package doubanhongniang
import com.google.gdata.data.douban.UserEntry;

class DoubanUser {
	String uid
	String location=''
	String email=''
	boolean authorized=false
	
	static constraints = {
        uid(blank:false, unique:true)
        email(email:true)
    }
	
	static DoubanUser getOrCreatedAuthorizedUser(def entry) {
		def doubanUser = DoubanUser.findByUid(entry.uid)
		if(!doubanUser) {
			doubanUser = new DoubanUser(uid:entry.uid, authorized:true)
			if(entry.location != null) {
				doubanUser.location = entry.location
			}
			doubanUser.save()
		} else if(!doubanUser.authorized) {
			doubanUser.authorized = true
			doubanUser.save()
		}
		
		doubanUser
	}
}
